package com.hhj.demo.ImportDemo;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Created by KING on 2018/7/18.
 */
public class MyImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        System.out.println(importingClassMetadata.getAnnotationAttributes(EnableMyTest.class.getName()).toString().contains("onlySale"));

        //获取自定的@EnableLogInfo 信息 如果包含 onlySale 则只注入Sales class 否则 注入 Sales 和 Market 两个类
        if (importingClassMetadata.getAnnotationAttributes(EnableMyTest.class.getName()) != null
                && importingClassMetadata.getAnnotationAttributes(EnableMyTest.class.getName()).toString().contains("onlySale")) {
            return new String[]{Yellow.class.getName()};
        }

        // 将指定的类
        return new String[]{Blue.class.getName(), Yellow.class.getName()};
    }
}
